package top.kaoshanji.p3ch21d;

import java.util.ArrayList;
import java.util.List;

/**
 * 代码清单-p3ch21d-254页b：树枝构件
 * @author kaoshanji
 * ^_^
 * create time 2025/3/26 10:40
 */
public class Composite extends Component {

    // 构件容器
    private List<Component> componentList = new ArrayList<>();

    /**
     * 增加一个叶子构件或树枝构件
     * @param component Component
     */
    public void add(Component component) {
        this.componentList.add(component);
    }

    /**
     * 删除一个叶子构件或树枝构件
     * @param component Component
     */
    public void remove(Component component) {
        this.componentList.remove(component);
    }

    /**
     * 获得分支下的所有叶子构件和树枝构件
     * @return List<Component>
     */
    public List<Component> getChildren() {
        return this.componentList;
    }

}
